//---------------------------------------------------------------------------
#pragma hdrstop
#include "TransitionClass.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
CTransition::CTransition(TCanvas* canvas, int x, int y) : CObject(canvas, x, y) {
	name = transition_name + " " + IntToStr(namecount++);
	number = count++;
	description = "";
	form = true;
	state = false;
	canvas->Font->Name = main_font;
}
//---------------------------------------------------------------------------
void CTransition::show() {
	int s1 = side / 2;
	int s2 = side * transition_ratio / 2;
	canvas->Font->Color = main_clNFont;
	if (state)
		canvas->Pen->Color = main_clActive;
	else
		canvas->Pen->Color = main_clBorder;
	if (form) {
		canvas->Rectangle(x - s1, y - s2, x + s1, y + s2);
		canvas->TextOutA(x - s1 + 3, y - canvas->Font->Size, number);
	}
	else {
		canvas->Rectangle(x - s2, y - s1, x + s2, y + s1);
		canvas->TextOutA(x - s2 + 3, y - s1 + 3, number);
	}
}
//---------------------------------------------------------------------------
void CTransition::hide() {
	canvas->Pen->Color = clWhite;
	int s1 = side / 2;
	int s2 = side * transition_ratio / 2;
	if (form)
		canvas->Rectangle(x - s1, y - s2, x + s1, y + s2);
	else
		canvas->Rectangle(x - s2, y - s1, x + s2, y + s1);
}
//---------------------------------------------------------------------------
bool CTransition::isSelect(int xm, int ym) {
	int s1 = side / 2;
	int s2 = side * transition_ratio / 2;
	if (form)
		if (x - s1 <= xm && xm <= x + s1 && y - s2 <= ym && ym <= y + s2)
			return true;
		else
			return false;
	else if (x - s2 <= xm && xm <= x + s2 && y - s1 <= ym && ym <= y + s1)
		return true;
	else
		return false;
}
//---------------------------------------------------------------------------
void CTransition::setSize(int size) {
	if (size < 10)
		size = 10;
	if (size > 19)
		size = 19;
	this->side = size * transition_size_ratio;
	canvas->Font->Size = transition_font_scale[size - 10];
}
//---------------------------------------------------------------------------
void CTransition::setState(bool state) {
	this->state = state;
}
//---------------------------------------------------------------------------
void CTransition::setForm(bool form) {
	this->form = form;
}
//---------------------------------------------------------------------------
bool CTransition::getState() {
	return state;
}
//---------------------------------------------------------------------------
bool CTransition::getForm() {
	return form;
}
//---------------------------------------------------------------------------
UnicodeString CTransition::save() {
	UnicodeString str = "", n = name, d = description;
	for (int i = 1; i <= n.Length(); i++)
		if (n[i] == ' ')
			n[i] = '`';
	for (int i = 1; i <= d.Length(); i++)
		if (d[i] == ' ')
			d[i] = '`';
	str += IntToStr(x) + " " + IntToStr(y) + " ";
	if (form)
		str += "1 ";
	else
		str += "0 ";
	if (d == "")
		d = "EMPTY_DESCRIPTION";
	str += n + " " + d;
	return str;
}
//---------------------------------------------------------------------------
CTransition::~CTransition() {
	count--;
	if (count < 0)
		count = 0;
}
//---------------------------------------------------------------------------
